package com.cgbl.cg.view

import android.content.Context
import androidx.recyclerview.widget.RecyclerView
import com.cgbl.cg.R
import com.cgbl.cg.adapter.FilterAdapter
import com.lxj.xpopup.core.BottomPopupView
import com.robot.base.view.CgTextView

class WorkMrvPop(
    context: Context,
    val title: String,
    val select: String,
    val list: ArrayList<String>
) : BottomPopupView(context) {
    private var confirmClickListener: (position: Int) -> Unit = {}
    private lateinit var recyclerView: RecyclerView
    private lateinit var selectCourseAdapter: FilterAdapter
    private lateinit var tvTitle: CgTextView

    override fun getImplLayoutId(): Int {
        return R.layout.app_pop_work_list
    }

    override fun initPopupContent() {
        super.initPopupContent()
        tvTitle = findViewById(R.id.tv_title)
        tvTitle.text = title
        recyclerView = findViewById(R.id.recyclerView)
        selectCourseAdapter = FilterAdapter(select)
        recyclerView.adapter = selectCourseAdapter
        selectCourseAdapter.setOnItemClickListener { adapter, view, position ->
            selectCourseAdapter.select = selectCourseAdapter.data[position]
            selectCourseAdapter.notifyDataSetChanged()
            confirmClickListener.invoke(position)
        }
        selectCourseAdapter.setNewInstance(list)
    }


    fun setConfirmClickListener(click: (position: Int) -> Unit): WorkMrvPop {
        confirmClickListener = click
        return this
    }

}